<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="utf-8">
	<link type="favicon" rel="shortcut icon" th:href="${domainName + 'static/images/favicon.png'}" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="renderer" content="webkit" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="author" content="SmartWiki" />
    <title>历史版本 - Tamguo</title>
    <link th:href="${domainName + 'static/bootstrap/css/bootstrap.min.css'}" rel="stylesheet">
    <link type="favicon" rel="shortcut icon" th:href="${domainName + 'static/images/favicon.png'}" />
    <script th:src="${domainName + 'static/jquery/1.12.4/jquery.min.js'}"></script>
    <style type="text/css">
        .container{margin: 5px auto;}
    </style>
</head>
<body>
<div class="container">
    <div class="table-responsive">
        <table class="table table-hover">
            <thead>
            <tr>
                <td class="col-sm-6">修改时间</td>
                <td class="col-sm-2">修改人</td>
                <td class="col-sm-2">操作</td>
            </tr>
            </thead>
            <tbody>
            
            <tr th:each="history,status:${historyList}">
                <td th:text="${#dates.format(history.updateDate, 'yyyy-MM-dd HH:mm:ss')}">2018-11-14 06:55:34</td>
                <td th:text="${history.owner}">admin</td>
                <td>
                    <button class="btn btn-danger btn-sm delete-btn" th:attr="data-id=${history.id}" data-loading-text="删除中...">
                        删除
                    </button>
                    <button class="btn btn-success btn-sm restore-btn" th:attr="data-id=${history.id}" data-loading-text="恢复中...">
                        恢复
                    </button>
                    
                    <button class="btn btn-success btn-sm compare-btn" th:attr="data-id=${history.id}">
                        合并
                    </button>
                    
                </td>
            </tr>
            
            </tbody>
        </table>
    </div>
</div>

<script th:src="${domainName + 'static/bootstrap/js/bootstrap.min.js'}"></script>
<script th:src="${domainName + 'static/layer/layer.js'}" type="text/javascript" ></script>
<script type="text/javascript">
    $(function () {
        $(".delete-btn").on("click",function () {
            var id = $(this).attr('data-id');
            var $btn = $(this).button('loading');
            var $then = $(this);

            if(!id){
                layer.msg('参数错误');
            }else{
                $.ajax({
                    url : "[[${domainName}]]" + "document/history/delete",
                    type : "post",
                    dataType : "json",
                    data : { "id" : id },
                    success :function (res) {
                        if(res.code === 0){
                            $then.parents('tr').remove().empty();
                        }else{
                            layer.msg(res.message);
                        }
                    },
                    error : function () {
                        $btn.button('reset');
                    }
                })
            }
        });

        $(".restore-btn").on("click",function () {
            var id = $(this).attr('data-id');
            var $btn = $(this).button('loading');
            var $then = $(this);
            var index = parent.layer.getFrameIndex(window.name);

            if(!id){
                layer.msg('参数错误');
            }else{
                $.ajax({
                    url : "[[${domainName}]]" + "document/history/restore",
                    type : "post",
                    dataType : "json",
                    data : { "id" : id },
                    success :function (res) {
                        if(res.code === 0){
                            var $node = { "node" : { "id" : res.result.id}};

                            parent.loadDocument($node);
                            parent.layer.close(index);
                        }else{
                            layer.msg(res.message);
                        }
                    },
                    error : function () {
                        $btn.button('reset');
                    }
                })
            }
        });
        $(".compare-btn").on("click",function () {
            var historyId = $(this).attr("data-id");

            window.compareIndex = window.top.layer.open({
                type: 2,
                title: '文档比较【左侧为历史文档，右侧为当前文档，请将文档合并到右侧】',
                shade: 0.8,
                area: ['380px', '90%'],
                content: "[[${domainName}]]" + "document/history/compare/" + historyId
            });
            window.top.layer.full(window.compareIndex);
        });
    });
</script>
</body>
</html>